﻿@model System.Data.DataTable           
@using Jb.Web.Utility;
@using Jb.Common.Extensions;
@using Jb.Common.DB;
@{
    bool _ShowForJobSeeker = NullHandler.GetBoolean(ViewData[AppConstants.ViewDataKeys.SHOW_EDIT_LINK]);
    bool _HideAddToFavorite = NullHandler.GetBoolean(ViewData[AppConstants.ViewDataKeys.HIDE_ADD_TO_FAVORITE]);
    int _TotalRecordToDisplay = Model == null ? 0 : Model.Rows.Count;
    List<int> _FavoriteResumes = new List<int>();
    if(UserInfo.IsCompanyUser){
        Jb.Domain.JbEntities context = new Jb.Domain.JbEntities();
        _FavoriteResumes = (from P in context.FavoriteResumes where P.CompanyID == SessionCache.CurrentUser.Contact.CompanyID select P.ResumeID).ToList();            
    }    

    MvcHtmlString _AdjustmentStyle = MvcHtmlString.Create(" style='margin-top: -10px;' ");
    if(WebUtil.IsMobileRequest()){
        _AdjustmentStyle = MvcHtmlString.Create(String.Empty);
    }        
}

@functions 
{
    public string GetFormattedDescription(String description)
    {
        if (description.WordCount() > 40)
            return String.Format("{0} ...", description.GetWords(40));
        
        return description;
    }
    public String GetResumeViewText(object downloadCount)
    {
        int count = NullHandler.GetInt(downloadCount);
        if (count == 0)
            return "Employers never downloaded this resume.";
        else if (count == 1)
            return "One Employer downloaded this resume.";
        else
            return String.Format("This resume was downloaded {0} times.", count);
    }
}
@if (_TotalRecordToDisplay > 0)
{   
    <div>
    @for (int i = 0; i < Model.Rows.Count; i++)
    {
        System.Data.DataRow _Row = Model.Rows[i];
        int _ResumeID = NullHandler.GetInt(_Row["ID"]);
        String _JobSeekerPhoto = ImageManager.GetJobSeekerPhotoUrl(NullHandler.GetString(_Row["PhotoFile"]), NullHandler.GetInt(_Row["JobSeekerID"]));
        //String _ComapnyName = NullHandler.GetString(_Row["CompanyName"]);
        String _DownloadUrl = NullHandler.GetString(_Row["FileName"]);
        _DownloadUrl = !_DownloadUrl.IsNullOrEmpty() && String.Compare(_DownloadUrl, AppConstants.ValueOf.UNKNOWN) != 0 ?
            Url.ResumeDownloadUrl(_ResumeID) : String.Empty;
        String _Name = Html.FormatData(_Row["Name"]);        
        <div class="jb-job row-fluid">
            <div class="span2 jb-left-padding">
                <img class="jb-js-photo" src="@(_JobSeekerPhoto)" alt="@(_Name)" title="@(_Name)" />
            </div>

            <div class="span10 jb-left-padding jb-right-padding">
            <div@(_AdjustmentStyle)><h2><small><a href="@(_DownloadUrl)">@Html.FormatData(_Row["Title"])</a></small></h2></div>
            @*<div class="clearfix"></div>*@
            <div class="jb-label-hint">
                Name: @Html.FormatData(_Row["Name"])<br />
                Last Updated On: @Html.FormatData(_Row["ModifiedOn"])
                @if(_ShowForJobSeeker){
                    if (NullHandler.GetBoolean(_Row["IsDefault"]))
                    {
                        <span class="label label-success">Default Resume</span>
                    }
                    else{
                        <span class="label label-warning">Not Default Resume</span>
                    }
                    <br />
                    <span class="label label-info">@GetResumeViewText(_Row["DownloadedCount"])</span>
                }
            </div>
            <div>
                @*<img class="jb-js-photo" src="@(_JobSeekerPhoto)" alt="@(_Name)" title="@(_Name)" align="left" />*@
                @Html.Raw(Html.FormatData(GetFormattedDescription(NullHandler.GetString(_Row["SnapShot"]))))
            </div>
            <div>
                @if(!_DownloadUrl.IsNullOrEmpty()) {
                <a href="@(_DownloadUrl)" class="btn btn-primary btn-mini" rel="tooltip" data-original-title="@(_Row["FileName"])"><i class="icon-download-alt icon-white"></i> Download</a>
                }
                @if (UserInfo.IsCompanyUser && !_HideAddToFavorite)
                {
                    if (_FavoriteResumes.Contains(_ResumeID))
                    {
                        <button class="btn btn-mini disabled" type="button" onclick="AddToFavoriteResume(@_ResumeID, this);"><i class="icon-star"></i> Added to Favorite</button>
                    }
                    else
                    {
                        <button class="btn btn-mini" type="button" onclick="AddToFavoriteResume(@_ResumeID, this);"><i class="icon-star"></i> Add to Favorite</button>
                    }
                }
                @if (_ShowForJobSeeker)
                {   
                    <a href='javascript:void(0);' class='btn btn-mini delete-resume' delete-resume-id='@_ResumeID'><i class="icon-remove"></i> Delete</a>
                    <a href="/JobSeeker/Resume/Edit/@(_ResumeID)" class="btn btn-mini"><i class='icon-edit'></i> Edit</a>
                }                
            </div>
            </div>@*Span9 End*@
        </div>
        @*<div class="clearfix"></div>*@
    } 
    </div>   
}
@*End of if _TotalRecordToDisplay > 0*@

